/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.itschapala.dsw2.vista;

import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import mx.itschapala.dsw2.biblioteca.bl.UsuarioBlLocal;
import mx.itschapala.dsw2.biblioteca.modelo.Usuario;

/**
 *
 * @author Santiago
 */
@ManagedBean
@SessionScoped
public class AccessBean {

    @EJB
    private UsuarioBlLocal usuarioBl;
    /**
     * Creates a new instance of AccessBean
     */
    //--------------Variables Loales(propiedades)--------------------
    private String name;
    private String pass;
    //--------------Constructores------------------------------------

    public AccessBean() {
        
    }
    //--------------Metodos Get y Set--------------------------------

    public String getName() {
        System.out.println("Entro al Get");
        return name;
    }

    public void setName(String name) {
        System.out.println("Entro al Set");
        this.name = name;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }
//------------------Acciones----------------------------------

    public String validarLogin() {
        String pagina = "";
        for (Usuario usuario : usuarioBl.getAll()) {
            if (name.equals(usuario.getNombre()) && pass.equals(usuario.getClave())) {
                FacesContext context = FacesContext.getCurrentInstance();
                context.getExternalContext().getSessionMap().put("USUARIO_LOGEADO", name);
                pagina = "MenuPrincipal";
            } else {
                pagina = "pagina2";
            }
        }
        return pagina;
    }
//------------------Listeners----------------------------------
}
